/*
 * @lc app=leetcode.cn id=405 lang=typescript
 *
 * [405] 数字转换为十六进制数
 */

// @lc code=start
let reflect = [...Array(10).keys(), "a", "b", "c", "d", "e", "f"].map((i) =>
    i.toString()
);
function toHex(num: number): string {
    if (num === 0) return "0";
    if (num < 0) num = 16 ** 8 + num;
    let now = num;

    let result = "";
    while (now) {
        result = reflect[now % 16] + result;
        now = Math.floor(now / 16);
    }
    return result;
}
// @lc code=end
